class UserSys < ActiveRecord::Base
    include ActiveModel::Validations
    validates :login,:name, presence: true
    validates :login, uniqueness: true
    validates :login, length: { maximum: 30 }

    has_secure_password


    # before_create { generate_token(:auth_token) }
    #
    # def generate_token(column)
    #     begin
    #       self[column] = SecureRandom.urlsafe_base64
    #     end while UserSys.exists?(column => self[column])
    # end

    filterrific(
        available_filters: [
        :with_login,
        :with_name,
        :with_password_digest
    ]
    )
    # default for will_paginate
    self.per_page = 10

    scope :with_login, lambda { |ref_login|
      return nil  if ref_login.blank?
      where('user_sys.login like ?', '%' + ref_login.to_s + '%')
    }

    scope :with_name, lambda { |ref_name|
      return nil  if ref_name.blank?
      where('user_sys.name like ?', '%' + ref_name.to_s + '%')
    }


end
